package com.tsmti.system.dao.impl;

import com.tsmti.system.dao.NumberRuleDao;
import com.tsmti.core.common.dao.impl.BaseDaoImpl;
import com.tsmti.system.entity.NumberRules;
import org.springframework.orm.hibernate4.SessionFactoryUtils;
import org.springframework.stereotype.Repository;

import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.SQLException;
import java.sql.Types;
import java.util.List;

/**
 * Title：pims
 * Class：com.pims.dao.hibernate.config
 * Comapny:杭州同烁软件信息技术有限公司
 *
 * @author：周陈伟
 * @version：2.5 CreateTime：2017/1/22 22:31
 * Modify log:
 * Description：
 *
 */
@Repository("numberRuleDao")
public class NumberRuleDaoHibernate extends BaseDaoImpl implements NumberRuleDao {
    @Override
    public Long getNumber(int type, String orgId) throws SQLException {
        Connection c = SessionFactoryUtils.getDataSource(getSessionFactory()).getConnection();
        CallableStatement cs = c.prepareCall("{call proc_getSerialNo(?,?,?)}");
        Long number= 0L;
        try {
            cs.setInt(1, type);
            cs.setString(2, orgId);
            cs.registerOutParameter(3, Types.VARCHAR);
            cs.execute();
            number =  cs.getLong(3);
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            cs.close();
            c.close();
        }
        return number;
    }

}
